﻿using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using LanShellManager.Models;
using LanShellManager.ShellCommandServiceReference;

namespace LanShellManager.Controllers
{
    public class ShellCommandsRunController : Controller
    {
        private IShellCommandRun repository = new ShellCommandRunner();
        //private LanShellManagerContext db = new LanShellManagerContext();
        private IShellCommandRepository comandRepositorye = new ShellCommandRepository();
        private  IMachineRepository machineRepository= new MachineRepository();
        // GET: /ShelllCommmands/
        public ActionResult Index()
        {
            ShellCommandRunVm shellCommandRunVm = new ShellCommandRunVm();
            shellCommandRunVm.ShelllCommands = comandRepositorye.GetCommands();
            shellCommandRunVm.Machines = machineRepository.GetMachines();
            return View(shellCommandRunVm);
        }

        

        // POST: /Machines/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Index(FormCollection form)
        {
            if (ModelState.IsValid)
            {
                ShellCommandInfo commandInfo = new ShellCommandInfo();
                commandInfo.MachineName = form.Get("Machines");
                commandInfo.Text = form.Get("ShelllCommands");
                IShellCommand command=new ShellCommandClient();
                command.Execute(commandInfo);
                Thread.Sleep(3000);
                return RedirectToAction("Index","ShellCommandsResult");
            }
            return RedirectToAction("Index");
        }
    }

    internal class ShellCommandRunner : IShellCommandRun
    {
    }

    internal interface IShellCommandRun
    {
    }
}
